import QtQuick 2.1
import QtQuick.Controls 1.0
import QtQuick.Window 2.0
import QtQuick.Dialogs 1.0
import QtQuick.XmlListModel 2.0
import QtQuick.Controls.Styles 1.0

Rectangle {
    id: paneSkillEdit
    color: "lightsteelblue"
    clip: true


    Item {
        id: itemContent
        anchors.fill: parent
        anchors.margins: 6

        Item {
            id: itemTitle
            anchors.top: parent.top
            anchors.left: parent.left
            anchors.right: parent.right
            height: 20

            ComponentButton {
                id: buttonRemove
                anchors.right: parent.right
                anchors.verticalCenter: parent.verticalCenter
                anchors.left: undefined
                horizontalAlignment: Qt.AlignHCenter
                text: "-"
                width: 20

            }

            ComponentButton {
                id: buttonAdd
                anchors.right: buttonRemove.left
                anchors.verticalCenter: parent.verticalCenter
                anchors.left: undefined
                anchors.leftMargin: 6
                anchors.rightMargin: 6
                horizontalAlignment: Qt.AlignHCenter
                text: "+"
                width: 20
            }



            Text {
                id: textEditTitle
                text: "Skill"
                color: "white"
                anchors.left: parent.left
                anchors.right: buttonAdd.left
                anchors.verticalCenter: parent.verticalCenter
                font.pixelSize: 16
                font.bold: true
                clip: true
            }
        }

        
        Column {
            id: columnSkillName
            anchors.top: itemTitle.bottom
            anchors.left: parent.left
            anchors.right: parent.right
            anchors.margins: 2
            anchors.topMargin: 8
            spacing: 6
            
            Text {
                text: "Name"
                
                color: "white"
                font.bold: true;
            }
            
            Rectangle {
                anchors.left: parent.left
                anchors.right: parent.right
                height: 20
                
                color: "white"
                
                TextInput {
                    text: skillsModel.get(editIndex).name
                    anchors.fill: parent
                    verticalAlignment: TextInput.AlignVCenter
                    anchors.margins: 3
                    clip: true
                }
            }
        }
        
        Column {
            id: columnskillKeyAbilityibute
            anchors.top: columnSkillName.bottom
            anchors.left: parent.left
            anchors.right: parent.right
            anchors.margins: 2
            anchors.topMargin: 8
            spacing: 6

            Text {
                text: "Key Ability"

                color: "white"
                font.bold: true;
            }

            ComboBox {
                model: modelAttributes
                anchors.left: parent.left
                anchors.right: parent.right

                currentIndex: skillsModel.get(editIndex).keyAbility
                onCurrentIndexChanged: {
//                    if (skillsModel.rowCount > 0) {
                        /// \todo Replace XmlListModel with real data model, since XmlListModel is read only!
                        /// \author Jussi
                        /// \date 2013-10-10
//                        skillsModel.get(editIndex).skillKeyAbility = currentIndex;
//                    }
                }
            }
        }

        Column {
            id: columnArmorCheckPenalty
            anchors.top: columnskillKeyAbilityibute.bottom
            anchors.left: parent.left
            anchors.right: parent.right
            anchors.margins: 2
            anchors.topMargin: 8
            spacing: 6

            Text {
                anchors.left: parent.left
                anchors.right: parent.right

                text: "Armor Check Penalty"

                color: "white"
                font.bold: true;
            }

            ComponentCheckBox {
                anchors.left: parent.left
                anchors.right: parent.right
                text: "Applied"
                checkedState: skillsModel.get(editIndex).armorCheckPenalty ? Qt.Checked : Qt.Unchecked
            }

        } // columnArmorCheckPenalty


        Column {
            id: columnAction
            anchors.top: columnArmorCheckPenalty.bottom
            anchors.left: parent.left
            anchors.right: parent.right
            anchors.margins: 2
            anchors.topMargin: 8
            spacing: 6

            Text {
                anchors.left: parent.left
                anchors.right: parent.right

                text: "Action"

                color: "white"
                font.bold: true;
            }

            ListModel {
                id: modelActions
                ListElement { name: "Free" }
                ListElement { name: "Move" }
                ListElement { name: "Standard" }
            }

            ComboBox {
                model: modelActions
                anchors.left: parent.left
                anchors.right: parent.right
            }

        } // columnAction

        property int splitterStart: columnAction.y + columnAction.height
        property int splitterOffset: (height - splitterStart) / 5


        /// \todo Fix usability concerning splitters - maybe so that other inputs shrink automatically...
        /// \author Jussi
        /// \date 2013-10-24

        ComponentSplitter {
            id: splitterUntrained
            state: "horizontal"
            y: parent.splitterStart + parent.splitterOffset
            height: 3
            minimumDrag: parent.splitterStart + 87
            maximumDrag: splitterTryAgain.y - 87

        }

        Item {

            id: columnUntrained

            anchors.top: columnAction.bottom
            anchors.left: parent.left
            anchors.right: parent.right
            anchors.bottom: splitterUntrained.top
            anchors.margins: 2
            anchors.topMargin: 8


            Text {
                id: textUntrainedTitle
                anchors.top: parent.top
                anchors.left: parent.left
                anchors.right: parent.right

                text: "Trained Only"

                color: "white"
                font.bold: true;

                MouseArea {
                    anchors.fill: parent
                    cursorShape: Qt.PointingHandCursor
                    enabled: checkBoxUntrained.checked

                    onClicked: {
                        splitterSpecial.y = splitterSpecial.maximumDrag;
                        splitterCheck.y = splitterCheck.maximumDrag;
                        splitterTryAgain.y = splitterTryAgain.maximumDrag;
                        splitterUntrained.y = splitterUntrained.maximumDrag;
                    }
                }
            }

            ComponentCheckBox {
                id: checkBoxUntrained
                anchors.top: textUntrainedTitle.bottom
                anchors.left: parent.left
                anchors.right: parent.right
                anchors.topMargin: 6
                text: "Untrained"
                checkedState: skillsModel.get(editIndex).useUntrained ? Qt.Checked : Qt.Unchecked
                height: 14

                onCheckedChanged: {
                    textAreaUntrained.enabled = checked
                    if (!checked) {
                        splitterUntrained.y = splitterUntrained.minimumDrag
                    }
                }

            }

            TextArea {
                id: textAreaUntrained
                anchors.top: checkBoxUntrained.bottom
                anchors.left: parent.left
                anchors.right: parent.right
                anchors.bottom: parent.bottom
                anchors.topMargin: 6
                enabled: checkBoxUntrained.checked
            }

        } // columnUntrained

        ComponentSplitter {
            id: splitterTryAgain
            state: "horizontal"
            y: parent.splitterStart + parent.splitterOffset * 2
            height: 3

            minimumDrag: splitterUntrained.y + 87 //splitterUntrained.height + 60 + 14 + 8
            maximumDrag: splitterCheck.y - 67
        }

        Item {
            id: columnTryAgain
            anchors.top: splitterUntrained.bottom
            anchors.left: parent.left
            anchors.right: parent.right
            anchors.bottom: splitterTryAgain.top
            anchors.margins: 2
            anchors.topMargin: 4

            Text {
                id: textTryAgainTitle
                anchors.top: parent.top
                anchors.left: parent.left
                anchors.right: parent.right

                text: "Try Again"

                color: "white"
                font.bold: true;

                MouseArea {
                    anchors.fill: parent
                    cursorShape: Qt.PointingHandCursor
                    enabled: checkboxTryAgain.checked

                    onClicked: {
                        splitterUntrained.y = splitterUntrained.minimumDrag;

                        splitterSpecial.y = splitterSpecial.maximumDrag;
                        splitterCheck.y = splitterCheck.maximumDrag;
                        splitterTryAgain.y = splitterTryAgain.maximumDrag;
                    }
                }
            }

            ComponentCheckBox {
                id: checkboxTryAgain
                anchors.top: textTryAgainTitle.bottom
                anchors.left: parent.left
                anchors.right: parent.right
                text: "Yes"
                anchors.topMargin: 6
                checkedState: skillsModel.get(editIndex).tryAgain ? Qt.Checked : Qt.Unchecked
                height: 14

                onCheckedChanged: {
                    textAreaTryAgain.enabled = checked
                    if (!checked) {
                        splitterTryAgain.y = splitterTryAgain.minimumDrag
                    }
                }
            }

            TextArea {
                id: textAreaTryAgain
                anchors.top: checkboxTryAgain.bottom
                anchors.left: parent.left
                anchors.right: parent.right
                anchors.bottom: parent.bottom
                anchors.topMargin: 6
                enabled: checkboxTryAgain.checked
            }

        } // columnArmorCheckPenalty


        ComponentSplitter {
            id: splitterCheck
            state: "horizontal"
            y: parent.splitterStart + parent.splitterOffset * 3
            height: 3

            minimumDrag: splitterTryAgain.y + splitterTryAgain.height + 62
            maximumDrag: splitterSpecial.y - 67
        }

        Item {
            id: columnCheck
            anchors.top: splitterTryAgain.bottom
            anchors.right: parent.right
            anchors.bottom: splitterCheck.top
            anchors.left: parent.left
            anchors.margins: 2
            anchors.topMargin: 4

            Text {
                id: textCheckTitle
                anchors.left: parent.left
                anchors.right: parent.right

                text: "Check"

                color: "white"
                font.bold: true;

                MouseArea {
                    anchors.fill: parent
                    cursorShape: Qt.PointingHandCursor

                    onClicked: {
                        splitterUntrained.y = splitterUntrained.minimumDrag;
                        splitterTryAgain.y = splitterTryAgain.minimumDrag;

                        splitterSpecial.y = splitterSpecial.maximumDrag;
                        splitterCheck.y = splitterCheck.maximumDrag;
                    }
                }
            }

            TextArea {
                anchors.top: textCheckTitle.bottom
                anchors.right: parent.right
                anchors.bottom: parent.bottom
                anchors.left: parent.left
                anchors.topMargin: 6
            }

        } // columnCheck

        ComponentSplitter {
            id: splitterSpecial
            state: "horizontal"
            y: parent.splitterStart + parent.splitterOffset * 4

            height: 3

            minimumDrag: splitterCheck.y + splitterCheck.height + 62
            maximumDrag: parent.height - 67
        }

        Item {
            id: columnSpecial
            anchors.top: splitterCheck.bottom
            anchors.right: parent.right
            anchors.bottom: splitterSpecial.top
            anchors.left: parent.left
            anchors.margins: 2
            anchors.topMargin: 4

            Text {
                id: textSpecialTitle
                anchors.left: parent.left
                anchors.right: parent.right

                text: "Special"

                color: "white"
                font.bold: true;

                MouseArea {
                    anchors.fill: parent
                    cursorShape: Qt.PointingHandCursor

                    onClicked: {
                        splitterUntrained.y = splitterUntrained.minimumDrag;
                        splitterTryAgain.y = splitterTryAgain.minimumDrag;
                        splitterCheck.y = splitterCheck.minimumDrag;

                        splitterSpecial.y = splitterSpecial.maximumDrag;
                    }
                }
            }

            TextArea {
                anchors.top: textSpecialTitle.bottom
                anchors.right: parent.right
                anchors.bottom: parent.bottom
                anchors.left: parent.left
                anchors.topMargin: 6
            }

        } // columnSpecial

        Item {
            id: columnRestrictions
            anchors.top: splitterSpecial.bottom
            anchors.right: parent.right
            anchors.bottom: parent.bottom
            anchors.left: parent.left
            anchors.margins: 2
            anchors.topMargin: 4

            Text {
                id: textRestrictionsTitle
                anchors.left: parent.left
                anchors.right: parent.right

                text: "Restrictions"

                color: "white"
                font.bold: true;

                MouseArea {
                    anchors.fill: parent
                    cursorShape: Qt.PointingHandCursor

                    onClicked: {
                        splitterUntrained.y = splitterUntrained.minimumDrag;
                        splitterTryAgain.y = splitterTryAgain.minimumDrag;
                        splitterCheck.y = splitterCheck.minimumDrag;
                        splitterSpecial.y = splitterSpecial.minimumDrag;
                    }
                }
            }

            TextArea {
                anchors.top: textRestrictionsTitle.bottom
                anchors.right: parent.right
                anchors.bottom: parent.bottom
                anchors.left: parent.left
                anchors.topMargin: 6
            }
        } // columnRestrictions
    }

}


